//
//  LZBaseViewController.m
//  laziz_Consumer
//
//  Created by XMac on 16/10/24.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZBaseViewController.h"
#import "UINavigationBar+BackgroundColor.h"
#import "UIViewController+NavigationItemSetting.h"
#import "UIView+Rotation.h"
#import "UMMobClick/MobClick.h"
#import <MBProgressHUD/MBProgressHUD.h>

@interface LZBaseViewController ()
@property(nonatomic, strong) UIButton *nav_left_back;
@end

@implementation LZBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self configNavigationBackBarButtonItemTitle];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    if (self.umLogPageViewName) {
        [MobClick beginLogPageView:self.umLogPageViewName];
    }
    else {
        [MobClick beginLogPageView:@"其他页面"];
    }
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    
    if (self.umLogPageViewName) {
        [MobClick endLogPageView:self.umLogPageViewName];
    }
    else {
        [MobClick endLogPageView:@"其他页面"];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - private method

/**
 处理title偏右的情况
 */
- (void)configNavigationBackBarButtonItemTitle {
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
}

- (void)setUmLogPageViewName:(NSString *)umLogPageViewName {
    _umLogPageViewName = [umLogPageViewName copy];
}

- (CGFloat)fd_interactivePopMaxAllowedInitialDistanceToLeftEdge {
    return 50;
}

- (NSInteger)swipeType {
    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 9.0) {
        return [LZLanguageManager shareInstance].getLanguageType == LanguageType_Default;
    }
    // 滑动返回方向 ： 如果是阿拉伯语就返回 1  如果不是就返回 0
    return [LZLanguageManager shareInstance].getLanguageType == LanguageType_Ar;
}

#pragma mark - public method

/**
 添加loading
 
 @param aView 添加的父视图
 @param userInteractionEnabled 是否有动画效果
 */
- (void)startLoadingViewForView:(UIView*)aView loadingViewUserInteractionEnabled:(BOOL)userInteractionEnabled {
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:aView animated:YES];
    hud.userInteractionEnabled = userInteractionEnabled;
    hud.minSize = CGSizeMake(150, 100);                     // 菊花下边背景的大小
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;   // 设置菊花下边的背景不用高斯模糊
    hud.bezelView.color = UIColorFromRGB(0x000000, 0.4);    // 菊花下边的背景色
    hud.label.text = LZLocalizedString(@"refresh_loading", nil);    // 文字内容
    hud.contentColor = [UIColor whiteColor];                // 菊花和字体的背景色
}


/**
 移除loading
 
 @param aView 添加的父视图
 */
- (void)stopLoadingViewForView:(UIView*)aView {
    [MBProgressHUD hideHUDForView:aView animated:YES];
}

@end
